- /* sdfdsins.cpp by K.Tsuru */
- // function ID 3210 DRADIX
- /****************************************************
- SDouble class
- It provides the function sin x by series |x| < 1.0.
- *****************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* func = "SinSeries";
- SDouble SinSeries(const SDouble& x){
- // if(x.Sign(3210) == 0 ) return 0.0;//It does not check x==0 or not.
-
- SDouble sum(x), xsq(x*x), delta;
- ulong n = 4, den, mt = x.SlOpMaxValue();
- // check |x| < 1.0.
- if(x.NetRdxExp() > 1) sum.SetError(sum.OUT_OF_RANGE, func, 3210);
- sum.FixedPoint(x.RdxExp());
- delta = DsDiv(x*xsq, 6); //(x^3)/6
- sum -= delta;
-
- while(delta.Sign(3210)){// n(n+1) < x.SlOpMaxValue()
- den = n*(n+1); //The value of "den" does not discontinuously exceed ULONG_MAX.
- if(den >= mt) break;
- delta *= xsq;
- delta = DsDiv(delta, den);
- if(n & 2) sum -= delta;
- else sum += delta;
- n += 2;
- }
- while(delta.Sign(3210)){// n(n+1) >= x.SlOpMaxValue();
- if(n >= mt){
- sum.SetError(sum.NOT_CONVERGE, func, -3210); break;
- }
- delta *= xsq;
- delta = DsDiv(delta, n);
- delta = DsDiv(delta, n+1);
- if(n & 2) sum -= delta;
- else sum += delta;
- n += 2;
- }
- sum.PointFree();
- sum.Reform(3210);
- sum.upToTerm = n/2;
- return sum;
- }
sdfdsins.cpp : last modifiled at 2017/09/07 15:06:25(1,322 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).